<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow: hidden">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${Title}</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
 <!--Basic Styles-->
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel="stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style type="text/css">
    html, body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }    
    </style>
</head>
<body class="body-detail">
	<script>

		Page.onLoad(function(){
			mini.get('dg1').load();	
		});
		function doSearch(){
			mini.get('dg1').load({"FullName":$V('FullName')}) ;
			
			}
		function action(e) {
			//&nbsp;&nbsp;<a href="javascript:deleteUser(\'' + record.ID + '\','+record.Company+')">删除</a>
			var record = e.record
			e.cellStyle = "text-align:left";
	        return '<a href="javascript:viewUser(\'' + record.ID + '\','+record.Company+')">查看</a>';
		}
		function LifeAction(e){
			var record = e.record
			var date ="";
			if(record.Life){
				var days = "";
				var day = DateMinus(record.Life);
				if(day>0 && day<=30){
					days="  期限不足"+day+"天";
				}else if(day<0){
					days="  已过期";
				}else if(day==0){
					days="  期限不足1天";
				}
				if(days){
					date = new Date(record.Life).format("yyyy-MM-dd hh:mm:ss")+'<span style="color:red">'+days+'</span>';
				}else{
					date = new Date(record.Life).format("yyyy-MM-dd hh:mm:ss");
				}
			}else{
				date='<span style="color:red">未设置使用期限</span>';
			}
			return date;
			}

		function DateMinus(date){//date1:小日期   date2:大日期
		  　　var sdate = new Date(); 
		  　　var now = new Date(date); 
		  　　var days = now.getTime() - sdate.getTime(); 
		  　　var day = parseInt(days / (1000 * 60 * 60 * 24)); 
		  　　return day; 
		}

		Date.prototype.format = function(fmt)   
	    { //author: meizz   
	      var o = {   
	        "M+" : this.getMonth()+1,                 //月份   
	        "d+" : this.getDate(),                    //日   
	        "h+" : this.getHours(),                   //小时   
	        "m+" : this.getMinutes(),                 //分   
	        "s+" : this.getSeconds(),                 //秒   
	        "q+" : Math.floor((this.getMonth()+3)/3), //季度   
	        "S"  : this.getMilliseconds()             //毫秒   
	      };   
	      if(/(y+)/.test(fmt))   
	        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
	      for(var k in o)   
	        if(new RegExp("("+ k +")").test(fmt))   
	      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
	      return fmt;   
	    } 
		
		//查看用户
		function viewUser(member, company) {
			mini.open({
				width: 600,
				height : 500,
				title : "查看用户信息",
				url : "${ctx}eao/viewAdmin.jhtml?ID=" + member + "&Company=" + company,
				onOk: editSave,
			});
		}
		//编辑用户信息
		function editSave() {
			var form = $DW.mini.getForm('form2');
			form.validate();
			if(form.isValid() == false){
				return;
			}
			var dc = form.getData();
			if(dc.ContactPhone){
				if(!checkMobile(dc.ContactPhone)){
					top.mini.showTips({content:"联系电话格式不正确,请输入11位有效手机号!",state:'success'});
					return;
				}
			}
			
			if(dc.SecondPhone){
				if(!checkTel(dc.SecondPhone)){
					top.mini.showTips({content:"联系方式2格式不正确,请输入正确的座机号码!",state:'success'});
					return;
				}
			}
			
			if(dc.ThirdPhone){
				if(!checkTel(dc.ThirdPhone)){
					top.mini.showTips({content:"联系方式3格式不正确,请输入正确的座机号码!",state:'success'});
					return;
				}
			}
			
		 	Server.sendRequest("NewAccountNumber.updatePublicity", mini.encode(dc),function(response){
				if(response.Status == 1){
					top.mini.showTips({content:response.Message,state:'success'});
					$D.close();
					mini.get('dg1').reload();
				}else{
					top.mini.warn(response.Message);
				}
			}); 
		}
		//删除用户
		 function deleteUser(id, company) {
			top.mini.confirm("确定要删除？",function(action){
				if(action == "ok"){
					Server.sendRequest("NewAccountNumber.deleteEntId",{Id:id},function(response){
						if(response.Status == 1){
							top.mini.showTips({content:response.Message,state:'success'});
							mini.get('dg1').reload();
						}else{
							top.mini.warn(response.Message);
						}
					});
				}
			});
		} 
		function add(){
				mini.open({
					width:300,
					height:250,
					title:'新增一级账号',
					url:'${ctx}eao/addAdmin.jhtml',
					/* onOk: function (action) { 
						$D.close();
						mini.get('dg1').reload();
				    }, */
					ondestroy: function (action) { 
						$D.close();
						mini.get('dg1').reload();
				    }
				});
			}
		
		function addSave(){
			var form = $DW.mini.getForm('form3');
			if(form.validate() == false){
				return;
			}
			var dc = form.getData();
			Server.sendRequest("NewAccountNumber.addMember",dc,function(response){
				if(response.Status == 1){
					top.mini.showTips({content:response.Message,state:'success'});
					$D.close();
					mini.get('dg1').reload();
				}else{
					top.mini.warn(response.Message);
				}
			});
		}
		function removeMobil(){
		var Mobile = mini.get("Mobile").getValue();
		
		   top.mini.confirm("确定要删除？",function(action){
				if(action == "ok"){
					Server.sendRequest("NewAccountNumber.deleteEntId",{Mobile:Mobile},function(response){
					console.log(Mobile);
					console.log(response);
						 if(response.Status == 1){
							top.mini.showTips({content:response.Message,state:'success'});
							mini.get('dg1').reload();
						}else{
							top.mini.warn(response.Message);
						}
					});
				}
			});
		}

		 function checkMobile(str) {
			 var myreg=/^[1][3,4,5,6,7,8][0-9]{9}$/;
	         if (!myreg.test(str)) {
	             return false;
	         } else {
	             return true;
	         }

		 }
		 function checkTel(str) {
			 var myreg=/^([0-9]{3,4}-)?[0-9]{7,8}$/;
	         if (!myreg.test(str)) {
	             return false;
	         } else {
	             return true;
	         }

		 }
	</script>
 	<ef:init method="NewAccountNumber.findNumberEcMember">
		<div class="search-area">
			<div class="pull-left">
				<span>一级账号数量:${data }</span>
			 	<span>二级账号数量:${data2 }</span>
			 	<span>项目数量:${data3 }</span>
			</div>
			<div class="pull-right">
				<a class="mini-button" iconCls="icon-add" onclick="add();" plain="true">添加一级账号</a>
			    <!-- <input class="mini-textbox" id="Mobile" type="text" emptyText="请输入需要删除的手机号"/>
			 	<a class="mini-button" priv="RendanHeyi.SetSystemLayout.Expurgate"
					iconCls="icon-remove" onclick="removeMobil()" plain="true">删除</a>  -->
			<input class="mini-textbox" id="FullName" type="text" style="width:220px" emptyText="请输入机构名称、法人、联系人、账号"/>
			 	<button class="btn btn-default" id="Submitbutton" onClick="doSearch()"><i class="iconfont icon-search"></i></button>
			</div>
		</div>
	</ef:init>
	<div class="mini-fit" style="padding:0 10px 10px 10px;">
		<div id="dg1" class="mini-datagrid z-depth-1" style="width:100%;height:100%;" method="NewAccountNumber.findLevelAccount" idField="Id" multiSelect="true">
		    <div property="columns" align="center">
		    	<div type="indexcolumn"></div>
		    	<div field="Mobile" width="14%">账号</div>
		        <div field="FullName" width="14%">机构名称</div>
	            <div field="LegalRepresentative" width="6%">法人</div>
	            <div field="ContactName" width="6%">联系人</div>
	            <div field="ContactPhone" width="8%">联系电话</div>
	            <div  renderer="LifeAction"   width="14%" >使用期限</div>
	            <div name="action" renderer="action"  width="5%">操作</div>
		    </div>
		</div>
	</div>
</body>
</html>